#!/usr/bin/bash -l
source ~/anaconda3/bin/activate torch2
GPUS_PER_NODE=2
COUNT_NODE=1

accelerate launch --num_processes 2 \
--num_machines 1 \
--main_process_ip localhost \
--main_process_port 4224 \
--config_file accelerate_config.yaml \
run_accelerator_trainer.py

accelerate launch --num_processes 2 \
--num_machines 1 \
--main_process_ip localhost \
--main_process_port 4224 \
--config_file ds_config.yaml \
run_accelerator_trainer.py


optimizer_list=("Adam" "AdamW" "RMSprop" "SGD")
order_list=("fzbs" "fbsz" "zfbs" )

for optimizer in "${optimizer_list[@]}"; do
    for order in "${order_list[@]}"; do
        accelerate launch --num_processes 2 \
        --num_machines 1 \
        --config_file accelerate_config.yaml \
        issue.py --order $order --optimizer $optimizer
    done
done

for optimizer in "${optimizer_list[@]}"; do
    for order in "${order_list[@]}"; do
        awk '{split($0, arr, " - cuda:"); lines[arr[length(arr)]] = lines[arr[length(arr)]] $0 "\n";} END {for (i = 0; i <= 1; i++) {if (lines[i]) {printf "%s", lines[i];}}}' $optimizer-$order.txt >> $optimizer-$order.txt.p
    done
done
